//快速排序

#include <stdio.h>

void quick_sort(int *arr, int maxlen, int begin, int end);
void swap(int *a, int *b);
void show(int *arr, int len);

int main()
{
    int drr[] = {1, 8, 7, 5, 0};
    int num = sizeof(drr) / sizeof(drr[0]);
    quick_sort(drr, num, 0, num - 1);
    show(drr, num);
    return 0;
}

void quick_sort(int *arr, int maxlen, int begin, int end)
{
    int i, j;
    if (begin < end)
    {
        i = begin + 1;
        j = end;
        while (i < j)
        {
            if (arr[i] > arr[begin])
            {
                swap(&arr[i], &arr[j]);
                j--;
            }
            else
            {
                i++;
            }
        }
        if (arr[i] >= arr[begin])
        {
            i--;
        }
        swap(&arr[begin], &arr[i]);
        quick_sort(arr, maxlen, begin, i);
        quick_sort(arr, maxlen, j, end);
    }
}

void swap(int *a, int *b)
{
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
}

void show(int *arr, int len)
{
    for (int i = 0; i < len; i++)
    {
        printf("%d ", arr[i]);
    }
    printf("\n");
}